//
//  HAODE
//
//  Created by panquanReabam.com on 15/9/23.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//
#import "OrderExtAddViewController.h"
#import "ZJSwitch.h"
#import "MJRefresh.h"
#import "MemberCouponCell.h"
#import "MemberListViewController.h"
#import "CategoryListViewController.h"
#import "ChoosePaymentViewController.h"
#import "MemberAddressViewController.h"
#import "OrderExtHeaderView.h"
#import "OrderExtHeaderModel.h"
#import "TheCustomExtHeaderModel.h"
#import "OrderExtFooterView.h"
#import "OrderExtFooterModel.h"
#import "HasSpecFmdbTool.h"
#import "NoSpecFmdbTool.h"
#import "SelectedGoodNewViewController1.h"
#import "ReabamSingleton.h"
#import "GuideListViewController.h"
#import "GetAddBuyGoodsView.h"
#import "GetAddBuyGoodsViewController1.h"
#import "DeleteNull.h"
@interface OrderExtAddViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UITextViewDelegate,UITableViewDelegate,UITableViewDataSource,MemberListViewControllerDelegate,OrderExtHeaderViewDelegate,MemberAddressViewControllerDelegate,OrderExtFooterViewDelegate,CategoryListViewControllerDelegate,SelectedGoodDelegate,GuideListViewControllerDelegate,GuideListViewControllerDelegate,GetAddBuyGoodsViewController1Delegate>
@end
@implementation OrderExtAddViewController
{
    OrderExtFooterView*FooterView;
    OrderExtHeaderView*HeaderView;
    NSMutableArray*DiscountRatecode ;
    NSMutableArray*DiscountRatecontent;
    NSMutableArray*OrderDocTypeContent;
    NSMutableArray*OrderDocTypeCode;
    double saveAccount;
    NSString*totalMoney;
    UILabel*youhuiquanjine;
    UIButton*totalPriceLabel;
    UIButton*deductionPriceLabel;
    NSString*remakesAmountStr;
    NSMutableArray*title;
    NSMutableArray*couponType;
    NSMutableArray*discount;
    NSMutableArray*couponId ;
    NSMutableArray*price ;
    NSMutableArray*couponIds ;
    NSMutableArray*prices ;
    NSString* userToken;
    
    NSString* isCurrentMemberIdStr;
    UITableView*table;
    NSString *formattedNumberString;
    NSString *totalPromotionMoney;
    ReabamSingleton*commdity;
    NSMutableArray*staffIdArray;
    NSMutableArray*staffNameArray;
    NSMutableArray*codeArray;
    GetAddBuyGoodsView*GoodsView;
    
    NSMutableArray *headerModelArray;
    NSMutableArray *isCurrent;
    NSMutableArray *isAvailable;
    NSMutableArray *planId;
    NSMutableArray *sptypeName;
    NSMutableArray *sptype;
    NSMutableArray *planTitle;
    UIView*modifyThePreferentialView;
    UITableView*table_list;
    NSString*planIdTag;
    NSString*str1;NSString*str2;NSString*str3;NSString*str4;NSString*str5;NSString*str6;
    
    NSString*planIdStr;
    NSString*pidStr;
    NSString*docType;
    NSString*docTypeName;
    NSDictionary*ShopCartConfirmDic;
    NSString*takeExpiryDateStr;
}
@synthesize alt = alt;
@synthesize mDelegate;
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    commdity=[[ReabamSingleton shared]init];
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1]];
    lineLabel.alpha=1;
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    self.title=@"确认订单";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateMemberIds) name:@"updateMemberId" object:self.memberDict];
    
}
#pragma mark headerViewDelegate
-(void)updateMemberIds{//更新会员id算mdiscountMoney
    self.memberDict=commdity.dataMemberDict;
    
    [self memberIdStr:[self.memberDict objectForKey:@"memberId" ]   userName:[self.memberDict objectForKey:@"userName" ] phone:[self.memberDict objectForKey:@"phone" ] sex:[self.memberDict objectForKey:@"sex" ] gradeName:[self.memberDict objectForKey:@"gradeName" ]    consigneeName:[self.memberDict objectForKey:@"consigneeName" ] consigneeAddr:[self.memberDict objectForKey:@"consigneeAddr" ] consigneePhone:[self.memberDict objectForKey:@"consigneePhone" ] mdiscountMoney:@""];
}
-(void)selectCodeNameArray:(NSMutableArray *)selectCodeNameArrays selectNameArray:(NSMutableArray *)selectNameArrays selectIdNameArray:(NSMutableArray *)selectIdNameArrays{
    
    staffIdArray=selectIdNameArrays;
    staffNameArray=selectNameArrays;
    codeArray=selectCodeNameArrays;
    if (staffNameArray.count>=1) {
        str1=staffNameArray[0];
    }else{
        str1=@"";
    }
    if (staffNameArray.count>=2){
        str2=staffNameArray[1];
    }else{
        str2=@"";
    }
    if (staffNameArray.count>=3){
        str3=staffNameArray[2];
        
    }else{
        str3=@"";
    }
    if (staffNameArray.count>=4){
        str4=staffNameArray[3];
        
    }else{
        str4=@"";
    }
    if (staffNameArray.count>=5){
        str5=staffNameArray[4];
        
    }else{
        str5=@"";
    }
    if (staffNameArray.count>=6){
        str6=staffNameArray[5];
        
    }else{
        str6=@"";
    }
    [HeaderView.staffNameBtn setTitle:[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",str1,str2,str3,str4,str5,str6] forState:UIControlStateNormal];
    
}
-(void)closeKeyBoad
{
    [self.window makeKeyWindow];
    self.window.hidden=YES;
    [modifyThePreferentialView removeFromSuperview];
    
}

-(void)typeBtn:(NSString *)str{
    
    
    CategoryListViewController*de = [[CategoryListViewController alloc] init];
    de.code=OrderDocTypeCode;
    de.content=OrderDocTypeContent;
    de.sat=@"OrderDocType";
    de.mDelegate=self;
    [self.navigationController pushViewController:de animated:YES];
    
}

-(void)OrderDocType:(NSString *)OrderDocType OrderDocTypeCodeStr:(NSString *)OrderDocTypeCodeStr{
    if ([OrderDocTypeCodeStr isEqualToString:@"Retail"])
    {
        docType=@"Retail";
        docTypeName=@"零售";
        [HeaderView.typeBtn setTitle:@"零售" forState:UIControlStateNormal];
        self.DeliveryTypeCode=@"xcth";
        [FooterView.addressView removeFromSuperview];
        FooterView.ExpressFee.text=@"";
        FooterView.switchs.on=NO;
        FooterView.distributionView.frame=CGRectMake(0, FooterView.discountView.bottom, ScreenWidth, 120+155);
        [self ShopCartConfirm];
        [self reloadGoodInfoData];//从新刷新
        
    }else  if ([OrderDocTypeCodeStr isEqualToString:@"Booking"]){
        docType=@"Booking";
        docTypeName=@"预售";
        [HeaderView.typeBtn setTitle:@"预售" forState:UIControlStateNormal];
        [self reloadGoodInfoData];//从新刷新

    }else{
    
     docType=OrderDocTypeCodeStr;
     docTypeName=OrderDocType;
     [HeaderView.typeBtn setTitle:OrderDocType forState:UIControlStateNormal];
    [self reloadGoodInfoData];//从新刷新
    }
    
    
}

-(void)orderGive:(NSString *)str{
    
    GetAddBuyGoodsViewController1 *detailViewController = [[GetAddBuyGoodsViewController1 alloc] init];
    detailViewController.mDelegate=self;
    
    if ([[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"]objectForKey:@"sptype"]]isEqualToString:@"orderGive"]) {
        detailViewController.items=[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"];
        planIdStr=[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"planId"]];
        if ([[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"]count]>0) {
            detailViewController.chooseStr=@"重领赠品";
        }else{
            detailViewController.chooseStr=@"领赠品";
            
        }
    }else if ([[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"]objectForKey:@"sptype"]]isEqualToString:@"orderAddPrice"]){
        planIdStr=[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"planId"]];
        
        detailViewController.items=[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"];
        if ([[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"]count]>0) {
            detailViewController.chooseStr=@"重新换购";
        }else{
            detailViewController.chooseStr=@"去换购";
            
        }
    }
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
}
-(void)modifyTheBtn:(NSString *)str{
    isCurrent=[NSMutableArray array];
    isAvailable=[NSMutableArray array];
    planId=[NSMutableArray array];
    sptypeName=[NSMutableArray array];
    planTitle=[NSMutableArray array];
    sptype=[NSMutableArray array];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    modifyThePreferentialView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    modifyThePreferentialView.backgroundColor=[UIColor blackColor];
    modifyThePreferentialView.alpha=0.65;
    [self.window addSubview:modifyThePreferentialView];
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [modifyThePreferentialView addGestureRecognizer:singleFingerOne];
    //
    NSMutableArray* arr=[[NSMutableArray alloc]init];
    arr=[self.dataDictionary objectForKey:@"orderPlans"];
    
    for (NSDictionary* dicc in arr )
    {
        [isAvailable addObject:[dicc valueForKey:@"isAvailable"]];
        [isCurrent addObject:[dicc valueForKey:@"isCurrent"]];
        [planId addObject:[dicc valueForKey:@"planId"]];
        [planTitle addObject:[dicc valueForKey:@"planTitle"]];
        [sptypeName addObject:[dicc valueForKey:@"sptypeName"]];
        [sptype addObject:[dicc valueForKey:@"sptype"]];
        if ([[NSString stringWithFormat:@"%@", [dicc valueForKey:@"isAvailable"]]isEqualToString:@"Y"]&&[[NSString stringWithFormat:@"%@",[dicc valueForKey:@"isCurrent"]]isEqualToString:@"Y"]) {
            
            planIdStr=[NSString stringWithFormat:@"%@",[dicc valueForKey:@"planId"]];
        }
    }
    
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight-500, ScreenWidth, 500)];
    view.backgroundColor=[UIColor whiteColor];
    [self.window addSubview:view];
    UILabel*conditionsContenLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 30, ScreenWidth, 18)];
    [conditionsContenLabel setText:[NSString stringWithFormat:@"%@",@"修改优惠"]];
    conditionsContenLabel.font=[UIFont systemFontOfSize:15];
    conditionsContenLabel.textColor=qianheiColor;
    conditionsContenLabel.textAlignment=NSTextAlignmentCenter;
    [view addSubview:conditionsContenLabel];
    UILabel*lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 60-0.4, ScreenWidth-20, 0.45)];
    [lineLabel setBackgroundColor:qianhuiColor];
    [view addSubview:lineLabel];
    UIButton*cancelBtn =[[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40,-15,30, 30)];
    [cancelBtn setImage:[UIImage imageNamed:@"chas"] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(closeKeyBoad) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:cancelBtn];
    
    table_list = [[UITableView alloc]initWithFrame:CGRectMake(0, 60, ScreenWidth, 400) style:UITableViewStylePlain];
    table_list.delegate = self;
    table_list.dataSource = self;
    table_list.rowHeight = 45;
    table_list.separatorStyle=UITableViewCellSeparatorStyleNone;
    [table_list registerClass:[MemberCouponCell class] forCellReuseIdentifier:@"OrderExtAddViewController"];
    [view addSubview:table_list];
    
    [table_list reloadData];
    UIButton* tureBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 500-45, ScreenWidth, 45)];
    [tureBtn setTitle:@"确认" forState:UIControlStateNormal];
    [tureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    tureBtn.backgroundColor=luseColor;
    CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){204.0/255.0,153.0/255.0, 51.0/255.0, 1.0});
    [tureBtn.layer setBorderColor:tureBTncolorref];//边框颜色
    [tureBtn addTarget:self action:@selector(ture:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:tureBtn];
    
    
}
-(void)ture:(UIButton*)sender{
    pidStr=@"";
    [self memberIdStr];
}


-(void)chooseUserBtn:(NSString *)str{
    
    GuideListViewController *detailViewController = [[GuideListViewController alloc] init];
    detailViewController.mDelegate = self;
    detailViewController.selectedStaffIdArray=staffIdArray;
    detailViewController.selectedStaffNameArray=staffNameArray;
    detailViewController.selectedcodeArray=codeArray;
    [self.navigationController pushViewController:detailViewController animated:YES];
    
}
-(void)chooesBtn{
    MemberListViewController *detailViewController = [[MemberListViewController alloc] init];
    detailViewController.delegate = self;
    detailViewController.chooseState=@"选择";
    detailViewController.totalMoney=totalMoney;
    detailViewController.itemIdArray=self.itemIdArray;
    detailViewController.quantityArray=self.quantityArray;
    detailViewController.dealPriceArray=self.dealPriceArray;
    detailViewController.specIdArray=self.specIdArray;
    [self.navigationController pushViewController:detailViewController animated:YES];
    
}
-(void)goodInfoButtonClick
{
    SelectedGoodNewViewController1 *selectedGoodVC=[[SelectedGoodNewViewController1 alloc] init];
    selectedGoodVC.delegate=self;
    selectedGoodVC.typeString=self.saveTypeStr;
    selectedGoodVC.backType=@"backType";
    selectedGoodVC.memberDict=self.memberDict;
    selectedGoodVC.planIdStr=planIdStr;
    NSLog(@"---------planIdStrfdsjkhself.dataDictionary%@",planIdStr);
    [self.navigationController pushViewController:selectedGoodVC animated:YES];
}
#pragma mark SelectedGood delegate

-(void)updates:(NSString *)updateItemIdStr :(NSString *)updateSpecIdStr :(NSString *)updatepidStr{
    
    pidStr=updatepidStr;
    [self reloadGoodInfoData];
}
-(void)deleteBtnBtn:(NSString *)str{
    pidStr=nil;
    [self reloadGoodInfoData];//从新刷新
    
}
-(void)reloadGoodInfoData:(NSString*)planIds{
    planIdStr=planIds;
    NSLog(@"---------planIdStrfdsjkhself.dataDictionary%@",planIdStr);
    [self reloadGoodInfoData];//从新刷新
}
-(void)reloadGoodInfoData
{
    NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
    [params setObject:userToken forKey:@"tokenId"];
    [params setObject:[NSString stringWithFormat:@"%@",isCurrentMemberIdStr] forKey:@"memberId"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Business/ShopCart/Detail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                [self memberIdStr];
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
                
            }
            
        }else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
    }];
}
-(void)memberIdStr{
    
    [self.itemIdArray removeAllObjects];
    [self.specIdArray removeAllObjects];
    [self.dealPriceArray removeAllObjects];
    [self.quantityArray removeAllObjects];
    
    NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
    [params setObject:userToken forKey:@"tokenId"];
    if (planIdStr!=nil) {
        [params setObject:planIdStr forKey:@"planId"];
    }else{
        
        [params setObject:@"" forKey:@"planId"];
    }
    [params setObject:[NSString stringWithFormat:@"%@",isCurrentMemberIdStr] forKey:@"memberId"];
    if (pidStr!=nil) {
        [params setObject:pidStr forKey:@"pid"];
    }else{
        
        [params setObject:@"" forKey:@"pid"];
    }
    if ([pidStr isEqualToString:@""]) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.window];
    }else{
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    }
    
    [HttpRequest requestData:@"Business/ShopCart/Confirm" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                NSLog(@"self.dataDictionary%@",severDataDict.dataDict);
                if ([pidStr isEqualToString:@""]) {
                    [Global hideProgressHUDInternal:self.window];
                }else{
                    [Global hideProgressHUDInternal:self.view];
                }
                [self.window makeKeyWindow];
                self.window.hidden=YES;
                [modifyThePreferentialView removeFromSuperview];
                self.dataDictionary=severDataDict.dataDict;
                self.dataDictionary=[DeleteNull changeType:self.dataDictionary];
                NSMutableArray* mItemsArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                for (NSDictionary *dic in mItemsArray) {
                    [self.itemIdArray addObject:[dic objectForKey:@"itemId"]];
                    [self.specIdArray addObject:[dic objectForKey:@"specId"]];
                    [self.dealPriceArray addObject:[dic objectForKey:@"dealPrice"]];
                    [self.quantityArray addObject:[dic objectForKey:@"quantity"]];
                    
                }
                
                totalPromotionMoney=[NSString stringWithFormat:@"%.2f",[[severDataDict.dataDict objectForKey:@"totalPromotionMoney"]doubleValue]];
                HeaderView.quantity=[NSString stringWithFormat:@"%.f",[[severDataDict.dataDict objectForKey:@"totalQty"]doubleValue]];
                HeaderView.dealPrice=[NSString stringWithFormat:@"%.2f",[[severDataDict.dataDict objectForKey:@"shopCartMoney"]doubleValue]];
                if ([[severDataDict.dataDict objectForKey:@"totalQty"] integerValue]==0) {
                }else{
                    
                    if (![[self.dataDictionary objectForKey:@"currentPlan"] isKindOfClass:[NSNull class]]){
                        HeaderView.currentPlan=[severDataDict.dataDict objectForKey:@"currentPlan"];
                        HeaderView.orderPlans=[severDataDict.dataDict objectForKey:@"orderPlans"];
                    }
                }
                HeaderView.takeExpiryDateStr=takeExpiryDateStr;
                HeaderView.saveTypeStr=self.saveTypeStr;
                HeaderView.consigneeName=self.consigneeName;
                HeaderView.consigneePhone=self.consigneePhone;
                HeaderView.consigneeAddr=self.consigneeAddr;
                HeaderView.delegate=self;
                HeaderView.type=docType;
                HeaderView.typeName=docTypeName;
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"###,##0.00;"];
                remakesAmountStr= [NSString stringWithFormat:@"%.2f",[[severDataDict.dataDict objectForKey:@"ySelRealMoney"]doubleValue]];
                totalMoney =[NSString stringWithFormat:@"%.2f",[[severDataDict.dataDict objectForKey:@"ySelRealMoney"]doubleValue]];
                
                
                
                OrderExtHeaderModel *dataModel=[OrderExtHeaderModel dataModelWithDict:self.memberId];
                HeaderView.model=dataModel;
                [HeaderView.discountTextFied addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
                [HeaderView.discountRateSatBtn addTarget:self action:@selector(discountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
                [HeaderView.jiantou addTarget:self action:@selector(discountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
                
                
                self.DeliveryTypeCode=@"xcth";
                [self DiscountRateSat];//重载优惠券数据为自定义首先
                [self selectCodeNameArray:codeArray selectNameArray:staffNameArray selectIdNameArray:staffIdArray];
                
                if (self.userName) {
                    HeaderView.phone=self.phone;
                    HeaderView.userName= self.userName;
                    HeaderView.sex=self.sex;
                    [self yzm];
                    [self DiscountRate:self.DiscountRate DiscountRateCode:self.DiscountRateCode];
                    table.tableHeaderView.frame=CGRectMake(0, 0, ScreenWidth, HeaderView.headerView.bottom);
                    table.tableHeaderView=HeaderView;
                }
                else
                {
                    HeaderView.phone=@"";
                    HeaderView.userName= @"";
                    HeaderView.sex=@"";
                    [self DiscountRate:self.DiscountRate DiscountRateCode:self.DiscountRateCode];
                    table.tableHeaderView.frame=CGRectMake(0, 0, ScreenWidth, HeaderView.headerView.bottom);
                    table.tableHeaderView=HeaderView;
                }}
            else
            {
                
                if ([pidStr isEqualToString:@""]) {
                    [Global hideProgressHUDInternal:self.window];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.window];
                    
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                }
                
            }
            
        }else
        {
            
            if ([pidStr isEqualToString:@""]) {
                [Global hideProgressHUDInternal:self.window];
                [Global showTextHudSub:severDataDict.resultStr view:self.window];
            }else{
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:severDataDict.resultStr view:self.view];
                
            }
            
            
        }
    }];
    
}

//更换地址
-(void)chooesAddressBtn:(NSString *)str{
    MemberAddressViewController *detailViewController = [[MemberAddressViewController alloc] init];
    detailViewController.chooseState=@"选择";
    detailViewController.delegate = self;
    detailViewController.userName=self.userName;
    detailViewController.phone =self.phone;
    detailViewController.sex=self.sex;
    detailViewController.memberId =self.memberId;
    [self.navigationController pushViewController:detailViewController animated:YES];
}
- (void)MemberAddressViewController:(MemberAddressViewController *)MemberAddressViewController
                        memberIdStr:(NSString *)memberIdStr userName:(NSString *)userName phone:(NSString *)phone sex:(NSString *)sex consigneeName:(NSString *)consigneeName consigneeAddr:(NSString *)consigneeAddr consigneePhone:(NSString *)consigneePhone
{
    self.consigneeName=consigneeName;
    self.consigneeAddr=consigneeAddr;
    self.consigneePhone=consigneePhone;
    self.DeliveryTypeCode=@"shsm";
    FooterView.consigneePhone=consigneePhone;
    FooterView.consigneeName=consigneeName;
    FooterView.address=consigneeAddr;
    OrderExtHeaderModel *dataModel=[OrderExtHeaderModel dataModelWithDict:@""];
    FooterView.OrderExtHeaderModel=dataModel;
    FooterView.mDelegate=self;
    
}
-(void)memberIdStr:(NSString *)memberIdStr userName:(NSString *)userName phone:(NSString *)phone sex:(NSString *)sex  gradeName:(NSString *)gradeName consigneeName:(NSString *)consigneeName consigneeAddr:(NSString *)consigneeAddr consigneePhone:(NSString *)consigneePhone mdiscountMoney:(NSString *)mdiscountMoney{
    self.userName=userName;
    self.phone=phone;
    self.sex=sex;
    self.memberId=memberIdStr;
    isCurrentMemberIdStr=memberIdStr;
    self.consigneeName=consigneeName;
    self.consigneeAddr=consigneeAddr;
    self.consigneePhone=consigneePhone;
    self.memberDict=commdity.dataMemberDict;
    
    self.dataDictionary=[DeleteNull changeType:self.dataDictionary];
    if ([self.orderType isEqualToString:@"order"]) {
        
        if ([[self.dataDictionary objectForKey:@"totalQty"]integerValue]==0) {
            
            
        }else{
            
if (![[self.dataDictionary objectForKey:@"currentPlan"] isKindOfClass:[NSNull class]]){
                
                if ([[self.dataDictionary objectForKey:@"currentPlan"]count]>0) {
                    
                    
                    if ([[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"isAvailable"]]isEqualToString:@"Y"]) {
                        
                        planIdStr=[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"planId"]];
                        if ([[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"sptype"]]isEqualToString:@"orderDown"]||[[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"sptype"]]isEqualToString:@"orderDiscount"]) {
                            
                        }else if ([[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"sptype"]]isEqualToString:@"orderGive"]||[[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"sptype"]]isEqualToString:@"orderAddPrice"]){
                            
                            for (int i = 0; i<[[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"]count]; i++) {
                                if ([[NSString stringWithFormat:@"%@",[[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"][i]objectForKey:@"isCurrent"]]isEqualToString:@"Y"]) {
                                    
                                    pidStr=[NSString stringWithFormat:@"%@",[[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"][i] objectForKey:@"pid"]];
                                }
                            }
                        }
                    }
                }
            }
        }
        
        HeaderView=[[OrderExtHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
        HeaderView.quantity=[NSString stringWithFormat:@"%.f",[[self.dataDictionary objectForKey:@"totalQty"]doubleValue]];
        HeaderView.dealPrice=[NSString stringWithFormat:@"%.2f",[[self.dataDictionary objectForKey:@"shopCartMoney"]doubleValue]];
        totalPromotionMoney=[NSString stringWithFormat:@"%.2f",[[self.dataDictionary objectForKey:@"totalPromotionMoney"]doubleValue]];
        if (![[self.dataDictionary objectForKey:@"currentPlan"] isKindOfClass:[NSNull class]]){
            HeaderView.currentPlan=[self.dataDictionary objectForKey:@"currentPlan"];
            HeaderView.orderPlans=[self.dataDictionary objectForKey:@"orderPlans"];}
        HeaderView.saveTypeStr=self.saveTypeStr;
        HeaderView.consigneeName=consigneeName;
        HeaderView.consigneePhone=consigneePhone;
        HeaderView.consigneeAddr=consigneeAddr;
        HeaderView.gradeName=gradeName;
        HeaderView.phone=phone;
        HeaderView.userName=userName;
        HeaderView.sex=sex;
        HeaderView.type=docType;
        HeaderView.typeName=docTypeName;
        HeaderView.delegate=self;
        OrderExtHeaderModel *dataModel=[OrderExtHeaderModel dataModelWithDict:memberIdStr];
        HeaderView.model=dataModel;
        [HeaderView.discountTextFied addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        [HeaderView.discountRateSatBtn addTarget:self action:@selector(discountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
        [HeaderView.jiantou addTarget:self action:@selector(discountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
        table.tableHeaderView.frame=CGRectMake(0, 0, ScreenWidth, HeaderView.headerView.bottom);
        table.tableHeaderView=HeaderView;
        [self reloadGoodInfoData];
        
        
    }else{
        
        HeaderView=[[OrderExtHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
        HeaderView.prices=self.prices;
        HeaderView.saveTypeStr=self.saveTypeStr;
        HeaderView.consigneeName=consigneeName;
        HeaderView.consigneePhone=consigneePhone;
        HeaderView.consigneeAddr=consigneeAddr;
        HeaderView.phone=phone;
        HeaderView.gradeName=gradeName;
        HeaderView.userName=userName;
        HeaderView.sex=sex;
        HeaderView.consigneeAddr=consigneeAddr;
        HeaderView.delegate=self;
        TheCustomExtHeaderModel *dataModel=[TheCustomExtHeaderModel dataModelWithDict:memberIdStr];
        HeaderView.TheCustomExtHeaderModel=dataModel;
        [HeaderView.discountTextFied addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        [HeaderView.discountRateSatBtn addTarget:self action:@selector(discountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
        [HeaderView.jiantou addTarget:self action:@selector(discountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
        prices=[[NSMutableArray alloc]init];
        couponType=[[NSMutableArray alloc]init];
        couponIds=[[NSMutableArray alloc]init];
        title=[[NSMutableArray alloc]init];
        self.DeliveryTypeCode=@"xcth";
        [self yzm];
        [self ShopCartConfirm];
        [self DiscountRateSat];//重载优惠券数据为自定义首先
        [self discountAmount:[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%.2f",totalMoney.doubleValue]]];
        
        HeaderView.frame=CGRectMake(0, 0, ScreenWidth, HeaderView.headerView.bottom);
        table.tableHeaderView=HeaderView;
        [self selectCodeNameArray:codeArray selectNameArray:staffNameArray selectIdNameArray:staffIdArray];
    }
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    docType=@"Retail";
    docTypeName=@"零售";
    planIdStr=@"";
    takeExpiryDateStr=@"";
    isCurrentMemberIdStr=@"";
    commdity=[[ReabamSingleton shared]init];
    self.itemIdArray=[[NSMutableArray alloc]init];
    self.specIdArray=[[NSMutableArray alloc]init];
    self.dealPriceArray=[[NSMutableArray alloc]init];
    self.quantityArray=[[NSMutableArray alloc]init];
    self.memberDict=commdity.dataMemberDict;
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    userToken = [user objectForKey:@"tokenId"];
    self.DeliveryTypeCode=@"xcth";
    self.dataDictionary=[DeleteNull changeType:self.dataDictionary];
    //    NSLog(@"self.dataDictionary%@",self.dataDictionary);
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    
    if ([self.orderType isEqualToString:@"order"]) {
        NSMutableArray* mItemsArray=[NSMutableArray arrayWithArray:[self.dataDictionary objectForKey:@"DataLine"]];
        if (mItemsArray.count>0) {
            for (NSDictionary *dic in mItemsArray) {
                
                [self.itemIdArray addObject:[dic objectForKey:@"itemId"]];
                [self.specIdArray addObject:[dic objectForKey:@"specId"]];
                [self.dealPriceArray addObject:[dic objectForKey:@"dealPrice"]];
                [self.quantityArray addObject:[dic objectForKey:@"quantity"]];
                
            }
        }
        
        totalPromotionMoney=[NSString stringWithFormat:@"%.2f",[[self.dataDictionary objectForKey:@"totalPromotionMoney"]doubleValue]];
        remakesAmountStr= [NSString stringWithFormat:@"%.2f",[[self.dataDictionary objectForKey:@"ySelRealMoney"]doubleValue]];
        totalMoney = [NSString stringWithFormat:@"%.2f",[[self.dataDictionary objectForKey:@"ySelRealMoney"]doubleValue]];
        formattedNumberString = [NSString stringWithFormat:@"%.2f",[[self.dataDictionary objectForKey:@"ySelRealMoney"]doubleValue]];
    }else{
        remakesAmountStr= self.prices;
        totalMoney = self.prices;
        formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:self.prices.doubleValue]];
        
    }
    
    
    
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    [table registerClass:[MemberCouponCell class] forCellReuseIdentifier:@"OrderExtAddViewController"];
    table.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
    
    HeaderView=[[OrderExtHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 320)];
    HeaderView.quantity=[NSString stringWithFormat:@"%.f",[[self.dataDictionary objectForKey:@"totalQty"]doubleValue]];
    totalPromotionMoney=[NSString stringWithFormat:@"%.2f",[[self.dataDictionary objectForKey:@"totalPromotionMoney"]doubleValue]];
    
    
    if ([[self.memberDict objectForKey:@"memberId"]length]>0) {//已经有会员
        [self updateMemberIds];
        
    }else{
        if ([self.orderType isEqualToString:@"order"]) {
            
            
            if ([[self.dataDictionary objectForKey:@"totalQty"]integerValue]==0) {
                
                
            }else{
                
                if (![[self.dataDictionary objectForKey:@"currentPlan"] isKindOfClass:[NSNull class]]){
                    if ([[self.dataDictionary objectForKey:@"currentPlan"]count]>0) {
                        
                        HeaderView.currentPlan=[self.dataDictionary objectForKey:@"currentPlan"];
                        HeaderView.orderPlans=[self.dataDictionary objectForKey:@"orderPlans"];
                        if ([[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"isAvailable"]]isEqualToString:@"Y"]) {
                            
                            planIdStr=[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"planId"]];
                            if ([[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"sptype"]]isEqualToString:@"orderDown"]||[[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"sptype"]]isEqualToString:@"orderDiscount"]) {
                                
                            }else if ([[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"sptype"]]isEqualToString:@"orderGive"]||[[NSString stringWithFormat:@"%@",[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"sptype"]]isEqualToString:@"orderAddPrice"]){
                                
                                for (int i = 0; i<[[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"]count]; i++) {
                                    if ([[NSString stringWithFormat:@"%@",[[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"][i]objectForKey:@"isCurrent"]]isEqualToString:@"Y"]) {
                                        
                                        pidStr=[NSString stringWithFormat:@"%@",[[[self.dataDictionary objectForKey:@"currentPlan"] objectForKey:@"items"][i] objectForKey:@"pid"]];
                                    }
                                }
                            }
                        }
                    }
                }
                
            }
            
            
            HeaderView.dealPrice=[NSString stringWithFormat:@"%.2f",[[self.dataDictionary objectForKey:@"shopCartMoney"]doubleValue]];
            HeaderView.type=docType;
            HeaderView.typeName=docTypeName;
            HeaderView. saveTypeStr=self.saveTypeStr;
            HeaderView.delegate=self;
            OrderExtHeaderModel *dataModel=[OrderExtHeaderModel dataModelWithDict:@""];
            HeaderView.model=dataModel;
            [self yzm];
            [self ShopCartConfirm];
            HeaderView.frame=CGRectMake(0, 0, ScreenWidth, HeaderView.headerView.bottom);
            table.tableHeaderView=HeaderView;
            
        }else{
            
            HeaderView=[[OrderExtHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 320)];
            HeaderView.prices=self.prices;
            HeaderView.delegate=self;
            TheCustomExtHeaderModel *dataModel=[TheCustomExtHeaderModel dataModelWithDict:@""];
            HeaderView.TheCustomExtHeaderModel=dataModel;
            [self yzm];
            [self ShopCartConfirm];
            HeaderView.frame=CGRectMake(0, 0, ScreenWidth, HeaderView.headerView.bottom);
            table.tableHeaderView=HeaderView;
        }
    }
    
    
    FooterView=[[OrderExtFooterView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 450)];
    FooterView.mDelegate=self;
    [FooterView.switchs addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    [HeaderView.discountTextFied addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [HeaderView.discountRateSatBtn addTarget:self action:@selector(discountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
    [HeaderView.jiantou addTarget:self action:@selector(discountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
    FooterView.discountAmountLabel.text=[NSString stringWithFormat:@"实付金额 ¥ %@" ,formattedNumberString];
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"实付金额 ¥ %@" ,formattedNumberString]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:13.0]
     
                          range:NSMakeRange(0, 6)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:zhonghuiColor
     
                          range:NSMakeRange(0, 6)];
    FooterView.discountAmountLabel.attributedText = AttributedStr;
    table.tableFooterView=FooterView;
    
    
    UIButton*viewBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-48, ScreenWidth*430/750, 48)];
    viewBtn.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    viewBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [viewBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    viewBtn.alpha=0.8;
    [self.view addSubview:viewBtn];
    totalPriceLabel=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-41, ScreenWidth*430/750, 41)];
    //    totalPriceLabel.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    totalPriceLabel.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [totalPriceLabel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    totalPriceLabel.alpha=0.8;
    [self priceStr:formattedNumberString];
    [self.view addSubview:totalPriceLabel];
    
    
    UIButton*buyBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*430/750, ScreenHeight-48, ScreenWidth*320/750, 48)];
    [buyBtn setTitle:@"去收银" forState:UIControlStateNormal];
    buyBtn.backgroundColor=luseColor;
    [buyBtn addTarget:self action:@selector(buy:) forControlEvents:UIControlEventTouchUpInside];
    [buyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:buyBtn];
    [self DiscountRateSat];
    
    
    staffIdArray=[[NSMutableArray alloc]init];
    staffNameArray=[[NSMutableArray alloc]init];
    codeArray=[[NSMutableArray alloc]init];
    
    
    NSString* fid = [user objectForKey:@"fid"];
    NSString* userName = [user objectForKey:@"userName"];
    NSString* code = @"10";
    staffIdArray=[NSMutableArray arrayWithObjects:fid, nil];
    staffNameArray=[NSMutableArray arrayWithObjects:userName, nil];
    codeArray=[NSMutableArray arrayWithObjects:code, nil];
    
    OrderDocTypeCode=[[NSMutableArray alloc]init];
    OrderDocTypeContent=[[NSMutableArray alloc]init];
    
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:userToken forKey:@"tokenId"];
    [param setValue:@"OrderDocType" forKey:@"optionName"];
    [HttpRequest requestData:@"System/AppCodes" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                NSLog(@"====%@",severDataDict.dataDict);
                
                [Global hideProgressHUDInternal:self.view];
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                for (NSDictionary* dicc in arrr )
                {
                    [OrderDocTypeCode addObject:[dicc valueForKey:@"code"]];
                    [OrderDocTypeContent addObject:[dicc valueForKey:@"content"]];
                }
                
                
            }else{
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }}
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];
    
}


#pragma mark - Table view data source
#pragma mark - Table view delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tableView == table) {
        return title.count;
    }
    return planId.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MemberCouponCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderExtAddViewController"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (tableView == table) {
        
        cell.saveAccount=YES;
        if ([[NSString stringWithFormat:@"%@",[price objectAtIndex:indexPath.row]]isEqualToString:@"0"]) {
            cell.title.text =[NSString stringWithFormat:@"%@ %@折",[title objectAtIndex:indexPath.row],[discount objectAtIndex:indexPath.row]];
            cell.title.font=[UIFont systemFontOfSize:15];
            cell.title.textColor=qianheiColor;
            NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@折",[title objectAtIndex:indexPath.row],[discount objectAtIndex:indexPath.row]]];
            NSInteger count = [[title objectAtIndex:indexPath.row]length];
            [AttributedStr addAttribute:NSFontAttributeName
             
                                  value:[UIFont systemFontOfSize:15.0]
             
                                  range:NSMakeRange(0, count)];
            
            [AttributedStr addAttribute:NSForegroundColorAttributeName
             
                                  value:zhonghuiColor
             
                                  range:NSMakeRange(0, count)];
            cell.title.attributedText = AttributedStr;

        }else{
        cell.title.text =[NSString stringWithFormat:@"%@ ¥ %@",[title objectAtIndex:indexPath.row],[price objectAtIndex:indexPath.row]];
        cell.title.font=[UIFont systemFontOfSize:15];
        cell.title.textColor=zhonghuiColor;
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ ¥ %@",[title objectAtIndex:indexPath.row],[price objectAtIndex:indexPath.row]]];
        NSInteger count = [[title objectAtIndex:indexPath.row]length];
        NSString *string=[NSString stringWithFormat:@"%@",[price objectAtIndex:indexPath.row]];
        NSInteger count1 =[string length];
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:15.0]
         
                              range:NSMakeRange(count, count1+3)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:qianheiColor
         
                              range:NSMakeRange(count, count1+3)];
        cell.title.attributedText = AttributedStr;
        }
        cell.xuanzeimage.image=[UIImage imageNamed:@"quans"];
       
        
        
        if  ([couponIds containsObject:[couponId objectAtIndex:indexPath.row]]){
            cell.xuanzeimage.image=[UIImage imageNamed:@"gous"];
            cell.saveAccount=NO;
            cell.conditions.text =[NSString stringWithFormat:@"¥ %@",[ShopCartConfirmDic objectForKey:@"couponMoney"]];
        }else{
         cell.conditions.text =@"";
        }
        
        if (couponId.count !=indexPath.row+1) {
            UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(10,45-0.5, ScreenWidth-20, 0.5)];
            _xianview.image=[UIImage imageNamed:@"hengxian"];
            [cell.contentView addSubview:_xianview];
            
        }
        if (indexPath.row==0) {
            UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(10,0, ScreenWidth-20, 0.5)];
            _xianview.image=[UIImage imageNamed:@"hengxian"];
            [cell.contentView addSubview:_xianview];
            
        }
    }
    
    if (tableView == table_list) {
        if (cell == nil) {
        }else{
            for (UIView *subView in cell.contentView.subviews)
            {
                [subView removeFromSuperview];
            }
        }
        
        NSString *s2 =[NSString stringWithFormat:@"%@", sptypeName[indexPath.row]];
        UIFont *font2 = [UIFont systemFontOfSize:11];
        CGSize size2 = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize2 = [s2 sizeWithFont:font2 constrainedToSize:size2 lineBreakMode:NSLineBreakByCharWrapping];
        cell.conditions =[[UILabel alloc]initWithFrame:CGRectMake(15,17, labelsize2.width, 13)];
        cell.conditions.textColor=[UIColor whiteColor];
        [cell.conditions.layer setCornerRadius:0.5];
        [cell.conditions.layer setBorderWidth:0.5];
        [cell.conditions.layer setMasksToBounds:YES];
        CGColorSpaceRef colorSpace12 = CGColorSpaceCreateDeviceRGB();
        CGColorRef colorref12 = CGColorCreate(colorSpace12,(CGFloat[]){ 252/255.0, 54/255.0, 30/255.0, 1.0 });
        [cell.conditions.layer setBorderColor:colorref12];//边框颜色
        cell.conditions.font=[UIFont systemFontOfSize:10];
        cell.conditions.text=sptypeName[indexPath.row];
        cell.conditions.textAlignment=NSTextAlignmentCenter;
        cell.conditions.backgroundColor=[UIColor redColor];
        [cell.contentView addSubview:cell.conditions];
        
        
        NSString *s =[NSString stringWithFormat:@"%@", planTitle[indexPath.row]];
        UIFont *font = [UIFont systemFontOfSize:14];
        CGSize size = CGSizeMake(ScreenWidth-labelsize2.width-15-50, 2000);
        CGSize labelsize= [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
        
        cell.conditionsLabel = [[UILabel alloc]initWithFrame:CGRectMake(cell.conditions.right+5,0, ScreenWidth-labelsize2.width-15-50, labelsize.height+30)];
        cell.conditionsLabel.textColor=shenhuiColor;
        cell.conditionsLabel.numberOfLines=0;
        cell.conditionsLabel.text=planTitle[indexPath.row];
        cell.conditionsLabel.font=[UIFont systemFontOfSize:14];
        [cell.contentView addSubview:cell.conditionsLabel];
        
        cell.chooseBtn1=[[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40, (labelsize.height+30)/2-15, 30, 30)];
        [cell.chooseBtn1 setUserInteractionEnabled:NO];
        if ([isCurrent[indexPath.row]isEqualToString:@"Y"]) {
            UIImage *img=[UIImage imageNamed:@"gous"];
            [cell.chooseBtn1 setImage:img forState:UIControlStateNormal];
        }else{
            
            
            UIImage *img=[UIImage imageNamed:@"quans"];
            [cell.chooseBtn1 setImage:img forState:UIControlStateNormal];
            
        }
        [cell.contentView addSubview:cell.chooseBtn1];
        
        
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(10, labelsize.height+30-0.40, ScreenWidth-20, 0.40)];
        lineLabel1.backgroundColor=qianhuiColor;
        [cell.contentView addSubview:lineLabel1];


    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == table_list) {
        
            NSString *s2 =[NSString stringWithFormat:@"%@", sptypeName[indexPath.row]];
            UIFont *font2 = [UIFont systemFontOfSize:11];
            CGSize size2 = CGSizeMake(ScreenWidth-60, 2000);
            CGSize labelsize2 = [s2 sizeWithFont:font2 constrainedToSize:size2 lineBreakMode:NSLineBreakByCharWrapping];
            
            NSString *s =[NSString stringWithFormat:@"%@", planTitle[indexPath.row]];
            UIFont *font = [UIFont systemFontOfSize:14];
            CGSize size = CGSizeMake(ScreenWidth-labelsize2.width-15-50, 2000);
            CGSize labelsize= [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
       
            
        

        return  labelsize.height+30;
    }
    return  45;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == table) {
        if ([couponIds containsObject:couponId[indexPath.row]]) {
            
            UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
            MemberCouponCell *sharecell=(MemberCouponCell *)cell;
            sharecell.xuanzeimage.image=[UIImage imageNamed:@"quans"];
            
            [prices removeAllObjects];
            [couponIds removeAllObjects];
        }else{
            
            for (int i=0;  i<couponId.count; i++) {
                NSIndexPath *indexPath1 =[NSIndexPath indexPathForRow:i inSection:0 ];
                UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath1];
                MemberCouponCell *sharecell=(MemberCouponCell *)cell;
                sharecell.xuanzeimage.image=[UIImage imageNamed:@"quans"];
            }
            UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
            MemberCouponCell *sharecell=(MemberCouponCell *)cell;
            sharecell.xuanzeimage.image=[UIImage imageNamed:@"gous"];
            prices=[[NSMutableArray alloc]init];
            couponIds=[[NSMutableArray alloc]init];
            [couponIds addObject:couponId[indexPath.row]];
            [prices addObject:price[indexPath.row]];
        }
        [self yzm];
        [self ShopCartConfirm];
    }else{
        if (tableView == table_list) {
            
            for (int i=0;  i<planId.count; i++) {
                NSIndexPath *indexPath1 =[NSIndexPath indexPathForRow:i inSection:0 ];
                UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath1];
                MemberCouponCell *sharecell=(MemberCouponCell *)cell;
                [sharecell.chooseBtn1 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
                 [isCurrent replaceObjectAtIndex:i withObject:@"N"];
            }
            
            UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
            MemberCouponCell *sharecell=(MemberCouponCell *)cell;
            [sharecell.chooseBtn1 setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
            [isCurrent replaceObjectAtIndex:indexPath.row withObject:@"Y"];
            if ([[NSString stringWithFormat:@"%@",sptype[indexPath.row]]isEqualToString:@"orderDown"]||[[NSString stringWithFormat:@"%@",sptype[indexPath.row]]isEqualToString:@"orderDiscount"]) {
                
                
            }else if ([[NSString stringWithFormat:@"%@",sptype[indexPath.row]]isEqualToString:@"orderGive"]||[[NSString stringWithFormat:@"%@",sptype[indexPath.row]]isEqualToString:@"orderAddPrice"]){
                
            }
            planIdStr=[NSString stringWithFormat:@"%@",planId[indexPath.row]];
            
            //             }else{
            //
            //                 UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"提示" message:@"不可选择" delegate:self cancelButtonTitle:nil otherButtonTitles:@"取消", nil];
            //                 [alertView show];
            //
        }
        
    }
}
-(void)yzm{
    if (couponIds.count>0) {
        FooterView.memberPhone=self.phone;
        OrderExtFooterModel *dataModel=[OrderExtFooterModel dataModelWithDict:self.DeliveryTypeCode ];
        FooterView.OrderExtFooterModel=dataModel;
    }else{
        [FooterView.verificationView removeFromSuperview];
        FooterView.discountView.frame=CGRectMake(0, 0, ScreenWidth, 50);
        if ([self.DeliveryTypeCode isEqualToString:@"shsm"]) {
            FooterView.addressView.frame=CGRectMake(0,FooterView.discountView.bottom, ScreenWidth, 175);
            FooterView.distributionView.frame=CGRectMake(0,FooterView.addressView.bottom, ScreenWidth, 120+155);
            
            self.DeliveryTypeCode=@"shsm";//运费加载和计算从新再算一遍
            FooterView.consigneePhone=self.consigneePhone;
            FooterView.consigneeName=self.consigneeName;
            FooterView.address=self.consigneeAddr;
            
            FooterView.orderAmount=[NSString stringWithFormat:@"%.2f",  totalMoney.doubleValue-HeaderView.discountTextFied.text.doubleValue];//除掉折扣但不除优惠券
            FooterView.memberId=self.memberId;
            OrderExtHeaderModel *dataModel=[OrderExtHeaderModel dataModelWithDict:@""];
            FooterView.OrderExtHeaderModel=dataModel;
            FooterView.mDelegate=self;
            
        }else{
            FooterView.switchs.on=NO;
            [FooterView.addressView removeFromSuperview];
            FooterView.distributionView.frame=CGRectMake(0,FooterView.discountView.bottom, ScreenWidth, 120+155);
        }
    }
}
-(void)switchAction:(UISwitch*)sender{
    if (self.memberId .length>0) {
        if ([docType isEqualToString:@"Retail"]) {
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"零售不能选择配送！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            alert.tag=1111;
            [alert show];
          
        }else  if ([docType isEqualToString:@"Booking"]){
            if (sender.on ==YES) {
                self.DeliveryTypeCode=@"shsm";//运费加载和计算
                FooterView.consigneePhone=self.consigneePhone;
                FooterView.consigneeName=self.consigneeName;
                FooterView.address=self.consigneeAddr;
                
                FooterView.orderAmount=[NSString stringWithFormat:@"%.2f",  totalMoney.doubleValue-HeaderView.discountTextFied.text.doubleValue];//除掉折扣但不除优惠券
                FooterView.memberId=self.memberId;
                OrderExtHeaderModel *dataModel=[OrderExtHeaderModel dataModelWithDict:@""];
                FooterView.OrderExtHeaderModel=dataModel;
                FooterView.mDelegate=self;
            }
            if (sender.on == NO) {
                self.DeliveryTypeCode=@"xcth";
                [FooterView.addressView removeFromSuperview];
                FooterView.ExpressFee.text=@"";
                FooterView.distributionView.frame=CGRectMake(0, FooterView.discountView.bottom, ScreenWidth, 120+155);
                [self ShopCartConfirm];
            }
            
        }else{
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"订单数据类型不对！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                alert.tag=1111;
            [alert show];
            
        }
        
        
    }else{
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择会员信息" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        alert.tag=1111;
        [alert show];
    }
}
-(void)buy:(UIButton *)sender {
    if ([docType isEqualToString:@"Retail"]) {
        
        
        [self pay];
        
    }else  if ([docType isEqualToString:@"Booking"]){
        if (isCurrentMemberIdStr.length>0) {
             if (takeExpiryDateStr.length>0) {
                  [self pay];
                       }else{
                           UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"预售情况下需要选择提货时间" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                           alert.tag=10000;
                           [alert show];

             }
        }else{
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"预售情况下需要选择会员信息" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
    }else{
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"订单数据类型不对！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        
    }

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag==1111) {
        if (buttonIndex == 0) {
          FooterView.switchs.on=NO;
        }
    }else if (alertView.tag==10000){
        if (buttonIndex == 0) {
           
        }
    }
}

-(void)pay{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:userToken forKey:@"tokenId"];
    [params setValue:self.userName forKey:@"memberName"];
    [params setValue:self.memberId forKey:@"memberId"];
    [params setValue:self.DeliveryTypeCode forKey:@"deliveryType"];
    [params setValue:FooterView.verificationCode.text forKey:@"msgCode"];
    if (couponIds.count>0) {
        [params setValue:couponIds forKey:@"couponIds"];
       [params setValue:   [NSString stringWithFormat:@"%@",[ShopCartConfirmDic objectForKey:@"couponMoney"]] forKey:@"couponMoney"];//优惠券金额
    }
    if ([HeaderView.discountTextFied.text isEqualToString:@""]) {
    }else{
        [params setValue:[NSString stringWithFormat:@"%@",[ShopCartConfirmDic objectForKey:@"discountMoney"]] forKey:@"discountMoney"];//discountMoney
    }
    [params setValue:self.consigneeAddr forKey:@"address"];
    [params setValue:self.consigneeName forKey:@"consignee"];
    [params setValue:self.consigneePhone forKey:@"phone"];
    [params setValue:FooterView.noteTextView.text  forKey:@"remark"];
    if (planIdStr!=nil) {
        [params setObject:planIdStr forKey:@"planId"];
    }
    if (pidStr!=nil) {
        [params setObject:pidStr forKey:@"pid"];
    }
    if ([self.OrderSat isEqualToString:@"GOrder/Add"] ) {
        [params setValue:totalMoney  forKey:@"totalMoney"];
        
    }else{
        [params setValue:takeExpiryDateStr  forKey:@"takeExpiryDate"];
        [params setValue:docType  forKey:@"docType"];
        [params setValue: [NSString stringWithFormat:@"%@",[ShopCartConfirmDic objectForKey:@"ySelRealMoney"]]  forKey:@"realMoney"];
        self.OrderSat=@"Order/Add";
        
    }
    NSMutableArray *staffsLine=[NSMutableArray array];
    for (int i=0; i<staffIdArray.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        NSString *staffId = [staffIdArray objectAtIndex:i];
        NSString *proportion = [codeArray objectAtIndex:i];
        [dic setValue:staffId forKey:@"staffId"];
        [dic setValue:proportion forKey:@"proportion"];
        [staffsLine addObject:dic];
    }
    [params setValue:staffsLine  forKey:@"staffs"];
    
    
    NSLog(@"33333333====%@",params);
    ChoosePaymentViewController  *generateVC=[[ChoosePaymentViewController alloc] init];
    generateVC.Dict=nil;
    generateVC.memberId=self.memberId;
    generateVC.orderSat=self.OrderSat;
    generateVC.saveTypeStr=self.saveTypeStr;
    generateVC.mcardPay=[ShopCartConfirmDic objectForKey:@"mcardPay"];
    generateVC.orderDict=[params mutableCopy];
    [self.navigationController pushViewController:generateVC animated:YES];
    
}
//1   一进来第一次为默认加载自定义类别   订单折扣百分比 discountRate／／／／／／订单定金百分比 earnestRate／／／／／／／／／／／／／／／／／／／／／／／／／
-(void)discountRateSatBtn:(UIButton *)sender {
    [self keyOn];
    CategoryListViewController*de = [[CategoryListViewController alloc] init];
    de.code=DiscountRatecode;
    de.content=DiscountRatecontent;
    de.sat=@"DiscountRate";
    de.mDelegate=self;
    [self.navigationController pushViewController:de animated:YES];
}

-(void)DiscountRateSat{
    DiscountRatecode=[[NSMutableArray alloc]init];
    DiscountRatecontent=[[NSMutableArray alloc]init];
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:userToken forKey:@"tokenId"];
    [param setValue:@"DiscountRate" forKey:@"optionName"];
    [HttpRequest requestData:@"System/AppCodes" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                for (NSDictionary* dicc in arrr )
                {
                    [DiscountRatecode addObject:[dicc valueForKey:@"code"]];
                    [DiscountRatecontent addObject:[dicc valueForKey:@"content"]];
                }
                
                if (DiscountRatecontent.count>0) {
                    [HeaderView.discountRateSatBtn setTitle:DiscountRatecontent[0] forState:UIControlStateNormal];
                    self.DiscountRateCode=DiscountRatecode[0];
                }
                
            }else{
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }}
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];
}
-(void)textViewEditing:(NSString *)textField{
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    table .frame =CGRectMake(0, -280, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
}
//回收键盘
-(void)OnTapDonekey:(NSString *)str{
     takeExpiryDateStr=HeaderView.takeExpiryDateTextFied.text;
    [self keyOn];
}
-(void)textFiedkey:(NSString *)str{
    prices=[[NSMutableArray alloc]init];
    couponIds=[[NSMutableArray alloc]init];
    [self ShopCartConfirm];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    table .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [self keyOn];
}
-(void)key:(NSString *)str{
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    table .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [self keyOn];
    
}
-(void)keyOn{
    
    [FooterView.verificationCode resignFirstResponder];
    [FooterView.noteTextView resignFirstResponder];
    [HeaderView.discountTextFied resignFirstResponder];
}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}
- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

-(void)xuanze:(UIButton*)sender
{      saveAccount=!saveAccount;
    if (saveAccount) {
        [sender setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
        youhuiquanjine.text=@"¥ 0";
        youhuiquanjine.textColor=hongseColor;
        youhuiquanjine.font=[UIFont systemFontOfSize:16];
        [FooterView addSubview:youhuiquanjine];
    }
    else
    {   [youhuiquanjine removeFromSuperview];
        [sender setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
    }
}
//算法／／／／／／／／／／／／／／／／／／／／／／／／／／／
//折扣算法
-(void)DiscountRate:(NSString *)DiscountRate DiscountRateCode:(NSString *)DiscountRateCode{
    prices=[[NSMutableArray alloc]init];
    couponIds=[[NSMutableArray alloc]init];
    self.DiscountRate=DiscountRate;
    self.DiscountRateCode=DiscountRateCode;
    if ([DiscountRateCode isEqualToString:@"0"]) {
        DiscountRate=@"自定义";
        DiscountRateCode=@"0";
    }
    [HeaderView.discountRateSatBtn setTitle:DiscountRate forState:UIControlStateNormal];
    double d2 = [DiscountRateCode doubleValue];
    if (d2==0) {
        HeaderView.discountTextFied.text=@"";
        [self ShopCartConfirm];
    }else {
        HeaderView.discountTextFied.text=[NSString stringWithFormat:@"%.2f",(totalMoney.doubleValue)*(1-d2)];
        [self ShopCartConfirm];
    }
}
-(void)textFieldEditing:(NSString *)textField{
    if (textField.intValue == 1)
    {
        [HeaderView.discountRateSatBtn setTitle:@"自定义" forState:UIControlStateNormal];//变回自定义按钮
        if ( [HeaderView.discountTextFied.text intValue]==0) {
            HeaderView.discountTextFied.text=@"";
        }
    }
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    table .frame =CGRectMake(0, -100, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
}
- (void)textFieldDidChange:(UITextField *) TextField{
    if (TextField.tag == 1)
    {
        if ([TextField.text doubleValue]<=[totalMoney doubleValue]) {
            
            if (0<=TextField.text.intValue&&TextField.text.length<99)
            {
                [HeaderView.discountRateSatBtn setTitle:@"自定义" forState:UIControlStateNormal];
            }
            
        }else{
            [self showAlertMessage:@"整单折扣金额不能高于商品总价！"];
            TextField.text=@"";
        }
        
    }
}
-(void)how:(NSString *)str{
    [self ShopCartConfirm];
}
-(void)ShopCartConfirm{//确认订单
    NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
    [params setObject:userToken forKey:@"tokenId"];
    if (planIdStr!=nil) {
        [params setObject:planIdStr forKey:@"planId"];
    }else{
        
        [params setObject:@"" forKey:@"planId"];
    }
    [params setObject:[NSString stringWithFormat:@"%@",isCurrentMemberIdStr] forKey:@"memberId"];
    if (couponIds.count>0) {
        [params setValue:couponIds forKey:@"couponIds"];
    }
    [params setValue:self.memberId forKey:@"memberId"];
    [params setValue:self.DeliveryTypeCode forKey:@"deliveryType"];
    if ([HeaderView.discountTextFied.text isEqualToString:@""]) {
    }else{
        [params setValue:HeaderView.discountTextFied.text forKey:@"discountMoney"];//discountMoney
    }
    if (pidStr!=nil) {
        [params setObject:pidStr forKey:@"pid"];
    }else{
        
        [params setObject:@"" forKey:@"pid"];
    }
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Business/ShopCart/Confirm" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
               NSLog(@"33333333====%@",severDataDict.dataDict);
                ShopCartConfirmDic=severDataDict.dataDict;
                [self discountAmount:[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"ySelRealMoney"]]];
                price=[[NSMutableArray alloc]init];
                title=[[NSMutableArray alloc]init];
                couponId=[[NSMutableArray alloc]init];
                couponType=[[NSMutableArray alloc]init];
                discount=[[NSMutableArray alloc]init];
                for (NSDictionary* dicc in [severDataDict.dataDict objectForKey:@"coupons"] )
            {
                [title addObject:[dicc valueForKey:@"title"]];
                [couponId addObject:[dicc valueForKey:@"couponId"]];
                [price addObject:[dicc valueForKey:@"price"]];
                [couponType addObject:[dicc valueForKey:@"couponType"]];
                [discount addObject:[dicc valueForKey:@"discount"]];
                }
            [table reloadData];

            }
        }else
            {
                
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:severDataDict.resultStr view:self.view];
            }
    }];

}
//实付金额所有优惠后显示的数据
-(void)discountAmount:(NSString *)formattedNumberStrings{

    [FooterView.discountAmountLabel removeFromSuperview];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString1 = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:formattedNumberStrings.doubleValue]];
    FooterView.discountAmountLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0, ScreenWidth-40, 45)];
    FooterView.discountAmountLabel.text=[NSString stringWithFormat:@"实付金额¥%@" ,formattedNumberString1];
    FooterView.discountAmountLabel.textColor=[UIColor blackColor];
    FooterView.discountAmountLabel.textAlignment = NSTextAlignmentRight;
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"实付金额 ¥ %@" ,formattedNumberString1]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:14.0]
     
                          range:NSMakeRange(0, 6)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:zhonghuiColor
     
                          range:NSMakeRange(0, 6)];
    FooterView.discountAmountLabel.attributedText = AttributedStr;
    [FooterView.distributionView addSubview:FooterView.discountAmountLabel];
    
    NSString *subString2 = [FooterView.discountAmountLabel.text substringFromIndex:6];
    [self priceStr:subString2];
}
-(void)priceStr:(NSString *)str {
    [deductionPriceLabel removeFromSuperview];
    deductionPriceLabel=[[UIButton alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth*430/750, 20)];
    deductionPriceLabel.titleLabel.font=[UIFont systemFontOfSize:11];
    deductionPriceLabel.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [deductionPriceLabel setTitleColor:zhonghuiColor forState:UIControlStateNormal];
    [totalPriceLabel addSubview:deductionPriceLabel];
    if ([[NSString stringWithFormat:@"%@",[ShopCartConfirmDic objectForKey:@"ySelPromotionMoney"]]intValue]!=0) {
        [deductionPriceLabel setTitle:[NSString stringWithFormat:@"   已优惠 ￥%.2f",[[ShopCartConfirmDic objectForKey:@"ySelPromotionMoney"] doubleValue]] forState:UIControlStateNormal];
        totalPriceLabel.contentVerticalAlignment=UIControlContentVerticalAlignmentTop;
        
    }else{
        totalPriceLabel.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        
    }
    [totalPriceLabel setTitle:[NSString stringWithFormat:@"   实付款￥%@",str] forState:UIControlStateNormal];
    NSMutableAttributedString *AttributedStr1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"   实付款￥%@",str]];
    totalPriceLabel.titleLabel.font=[UIFont systemFontOfSize:18];
    [AttributedStr1 addAttribute:NSFontAttributeName
     
                           value:[UIFont systemFontOfSize:13.0]
     
                           range:NSMakeRange(0, 7)];
    
    [AttributedStr1 addAttribute:NSForegroundColorAttributeName
     
                           value:[UIColor whiteColor]
     
                           range:NSMakeRange(0, 7)];
    
    
    totalPriceLabel.titleLabel.attributedText = AttributedStr1;
    
}
@end
